{%- macro user_avatar(user, class) -%}
  <a class="user-link user-avatar-link {{ class }}" href="{{ path('user_show', {id:user.id}) }}">
    <img src="{{ default_path('avatar',user.smallAvatar, '') }}">
  </a>
{%- endmacro -%}

{% macro user_link(user, class) %}
  {% if user %}
    <a {% if class %}class="{{ class }}"{% endif %} href="{{ path('user_show', {id:user.id}) }}">{{ user.nickname }}</a>
  {% else %}
    <span class="text-muted">用户已删除</span>
  {% endif %}
{% endmacro %}

{% macro flash_messages() %}
  {% for type, flashMessages in app.session.flashbag.all() %}
    {% for flashMessage in flashMessages %}
      <div class="alert alert-{{ type }}">{{ flashMessage|raw }}</div>
    {% endfor %}
  {% endfor %}
{% endmacro %}

{% macro bytesToSize(bytes) %}
  {% spaceless %}
      
      {% set kilobyte = 1024 %}
      {% set megabyte = kilobyte * 1024 %}
      {% set gigabyte = megabyte * 1024 %}
      {% set terabyte = gigabyte * 1024 %}

      {% if bytes < kilobyte %}
          {{ bytes ~ ' B' }}
      {% elseif bytes < megabyte %}
          {{ (bytes / kilobyte)|number_format(2, '.') ~ ' KB' }}
      {% elseif bytes < gigabyte %}
          {{ (bytes / megabyte)|number_format(2, '.') ~ ' MB' }}
      {% elseif bytes < terabyte %}
          {{ (bytes / gigabyte)|number_format(2, '.') ~ ' GB' }}
      {% else %}
          {{ (bytes / terabyte)|number_format(2, '.') ~ ' TB' }}
      {% endif %}

  {% endspaceless %}
{% endmacro %}

{% macro paginator(paginator) %}
  {% if paginator.lastPage > 1 %}
    <ul  class="pagination">
      {% if paginator.currentPage == paginator.firstPage %}
        <li class="disabled"><span>上一页</span></li>
      {% else %}
        <li><a  href="{{ paginator.getPageUrl(paginator.previousPage) }}">上一页</a></li>
      {% endif %}
      {% for page in paginator.pages %}
        <li {% if page == paginator.currentPage %}class="active"{% endif %}><a href="{{ paginator.getPageUrl(page) }}">{{ page }}</a></li>
      {% endfor %}

      {% if paginator.currentPage == paginator.lastPage %}
        <li class="disabled"><span>下一页</span></li>
      {% else %}
        <li><a  href="{{ paginator.getPageUrl(paginator.nextPage) }}">下一页</a></li>
      {% endif %}
    </ul>
  {% endif %}
{% endmacro %}